home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / java / vectors2 / quitdialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-07  |  2.4 KB  |  65 lines

  1. import java.awt.Button;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.Dialog;
  5. import java.awt.Event;
  6. import java.awt.FlowLayout;
  7. import java.awt.Frame;
  8. import java.awt.Rectangle;
  9.  
  10. public class QuitDialog extends Dialog {
  11.    Button yesButton;
  12.    Button noButton;
  13.  
  14.    void yesButton_Clicked(Event event) {
  15.       ((Component)this).getParent().handleEvent(new Event(this, 201, (Object)null));
  16.    }
  17.  
  18.    void noButton_Clicked(Event event) {
  19.       ((Component)this).hide();
  20.    }
  21.  
  22.    public QuitDialog(Frame parent, boolean modal) {
  23.       super(parent, modal);
  24.       ((Container)this).setLayout(new FlowLayout(1, 20, 20));
  25.       ((Dialog)this).addNotify();
  26.       ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 295, ((Container)this).insets().top + ((Container)this).insets().bottom + 92);
  27.       this.yesButton = new Button("Yes");
  28.       this.yesButton.reshape(((Container)this).insets().left + 51, ((Container)this).insets().top + 20, 60, 40);
  29.       ((Container)this).add(this.yesButton);
  30.       this.noButton = new Button("No");
  31.       this.noButton.reshape(((Container)this).insets().left + 165, ((Container)this).insets().top + 20, 60, 40);
  32.       ((Container)this).add(this.noButton);
  33.       ((Dialog)this).setResizable(false);
  34.    }
  35.  
  36.    public QuitDialog(Frame parent, String title, boolean modal) {
  37.       this(parent, modal);
  38.       ((Dialog)this).setTitle(title);
  39.    }
  40.  
  41.    public synchronized void show() {
  42.       Rectangle bounds = ((Component)this).getParent().bounds();
  43.       Rectangle abounds = ((Component)this).bounds();
  44.       ((Component)this).move(bounds.x + (bounds.width - abounds.width) / 2, bounds.y + (bounds.height - abounds.height) / 2);
  45.       super.show();
  46.    }
  47.  
  48.    public boolean handleEvent(Event event) {
  49.       if (event.id == 201) {
  50.          ((Component)this).hide();
  51.          return true;
  52.       } else {
  53.          if (event.target == this.noButton && event.id == 1001) {
  54.             this.noButton_Clicked(event);
  55.          }
  56.  
  57.          if (event.target == this.yesButton && event.id == 1001) {
  58.             this.yesButton_Clicked(event);
  59.          }
  60.  
  61.          return super.handleEvent(event);
  62.       }
  63.    }
  64. }
  65.